import java.util.Scanner;

public class Demo19 {
    //针对Demo18中出现的内存可见性问题，只需在变量前加上 volatile 即可以解决
    private static volatile int  flg=0;
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            while (flg==0){
                //循环体里面啥也不做
            }
            System.out.println("t1线程执行结束！");
        });
        Thread t2=new Thread(()->{
            Scanner scanner=new Scanner(System.in);
            flg=scanner.nextInt();
            System.out.println("t2线程执行结束！");
        });
        t1.start();
        t2.start();
    }
}
